package com.lzw.breezeNovel.webApp.service.impl.video;

import com.lzw.breezeNovel.model.entity.pojo.video.AnimeEpisode;
import com.lzw.breezeNovel.webApp.mapper.video.AnimeEpisodeMapper;
import com.lzw.breezeNovel.webApp.service.video.AnimeEpisodeService;
import com.lzw.breezeNovel.webApp.vo.video.AnimeEpisodeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.service.impl.video
 * @date 2025/3/20
 * @description 动漫的集
 */
@Slf4j
@Service
@SuppressWarnings("all")
public class AnimeEpisodeServiceImpl implements AnimeEpisodeService {

    /**
     * 注入mapper
     */
    @Autowired
    private AnimeEpisodeMapper animeEpisodeMapper;


    /**
     * 根据动漫ID查询动漫的集
     * @param animeId
     * @return
     */
    @Override
    @Transactional(readOnly = true)
    public List<AnimeEpisodeVo> getAnimeEpisodeByAnimeId(Long animeId) {
        List<AnimeEpisode> animeEpisodes = animeEpisodeMapper.getAnimeEpisodeByAnimeId(animeId);
        //判断是否为空
        if (animeEpisodes == null || animeEpisodes.isEmpty()) {
            return List.of();
        }
        //将animeEpisodes转换为AnimeEpisodeVo
        return animeEpisodes.stream().map(animeEpisode -> {
            AnimeEpisodeVo animeEpisodeVo = new AnimeEpisodeVo();
            BeanUtils.copyProperties(animeEpisode, animeEpisodeVo);
            return animeEpisodeVo;
        }).collect(Collectors.toList());
    }
}
